package com.develop.skwen.electricgomall.find;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.develop.skwen.basemodule.ui.BaseFragment;
import com.develop.skwen.electricgomall.find.list.FindListAdapter;
import com.develop.skwen.electricgomall.find.model.FindBean;
import com.develop.skwen.electricgomall.util.FindDataUtil;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.functions.Consumer;

/**
 * Created by skwen
 * on 18-5-29
 */

public class FindFragment extends BaseFragment<FindContract.FindPresenter,FindContract.FindVu> implements FindContract.FindPresenter {

    private List<FindBean> list = new ArrayList<>();
    private FindListAdapter adapter;

    @Override
    protected Class<? extends FindContract.FindVu> getVuClass() {
        return FindView.class;
    }

    @Override
    protected FindContract.FindPresenter getPresenter() {
        return this;
    }

    @Override
    protected void onBind() {

        adapter = new FindListAdapter(list);

        getVu().setAdapter(adapter);

        FindDataUtil.getInstance().getFindDatas(new Consumer<List<FindBean>>() {
            @Override
            public void accept(List<FindBean> findBeans) throws Exception {
                if (findBeans != null && findBeans.size() >0){
                    list.clear();
                    list.addAll(findBeans);
                    adapter.notifyDataSetChanged();
                }
            }
        });


    }

    @Override
    public void onRefresh() {
        getVu().stopRefresh();
    }

    @Override
    public RecyclerView.LayoutManager getLayoutManager() {
        return new LinearLayoutManager(getContext());
    }
}
